//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.abc.pay.client.ebpp;

import com.abc.pay.client.Base64;
import com.abc.pay.client.MerchantConfig;
import com.abc.pay.client.SignService;
import com.abc.pay.client.XMLDocument;
import java.util.ArrayList;

public class PaymentMerchant extends PaymentMerchantBean {
  private QueryRequestBean iQueryRequestBean = null;
  private StringBuffer iQueryResponseData = new StringBuffer();

  public StringBuffer getQueryResponseData() {
    return this.iQueryResponseData;
  }

  public PaymentMerchant(String aQRMessage) throws Exception {
    XMLDocument tQRMessage = new XMLDocument(aQRMessage);
    Base64 tBase64 = new Base64();
    String tQueryData = new String(tBase64.decode(tQRMessage.getValueNoNull("EBPPData")), "gb2312");
    if (tQueryData != null && !tQueryData.equals("")) {
      tQRMessage = new XMLDocument(tQueryData);
      this.iQueryRequestBean = new QueryRequestBean(tQRMessage);
    } else {
      new Exception("无查询条件！");
    }

  }

  public void setBillData(PaymentMerchantBean aPaymentMerchantBean) {
    this.iQueryResponseData.append("<BillData><BillNo>").append(aPaymentMerchantBean.getTBillNo()).append("</BillNo>");
    this.iQueryResponseData.append("<BillName>").append(aPaymentMerchantBean.getTBillName()).append("</BillName>");
    ArrayList tArr = aPaymentMerchantBean.getTPayerValueList();
    this.iQueryResponseData.append("<PayerValue1>").append(tArr.get(0)).append("</PayerValue1>");
    if (tArr.size() == 2) {
      this.iQueryResponseData.append("<PayerValue2>").append(tArr.get(1)).append("</PayerValue2>");
    } else {
      this.iQueryResponseData.append("<PayerValue2></PayerValue2>");
    }

    this.iQueryResponseData.append("<Amount>").append(aPaymentMerchantBean.getTAmount()).append("</Amount>");
    this.iQueryResponseData.append("<EffectDate>").append(aPaymentMerchantBean.getTEffectDate()).append("</EffectDate>");
    this.iQueryResponseData.append("<ExpiredDate>").append(aPaymentMerchantBean.getTExpiredDate()).append("</ExpiredDate>");
    this.iQueryResponseData.append("<CreateDate>").append(aPaymentMerchantBean.getTCreateDate()).append("</CreateDate>");
    this.iQueryResponseData.append("<Remark>").append(aPaymentMerchantBean.getTRemark()).append("</Remark>");
    this.iQueryResponseData.append("<Status>").append(aPaymentMerchantBean.getTStatus()).append("</Status>");
    this.iQueryResponseData.append("<VerifyDomain>");
    ArrayList tArr1 = aPaymentMerchantBean.getTVerifyDomainList();

    for(int i = 0; i < tArr1.size(); ++i) {
      this.iQueryResponseData.append("<VerifyName" + (i + 1) + ">").append(tArr1.get(i)).append("</VerifyName" + (i + 1) + ">");
    }

    this.iQueryResponseData.append("</VerifyDomain>");
    this.iQueryResponseData.append("<BillDetail>");
    ArrayList tArr2 = aPaymentMerchantBean.getTBillDetailList();

    for(int i = 0; i < tArr2.size(); ++i) {
      this.iQueryResponseData.append("<BillAttrName>").append(tArr2.get(i)).append("</BillAttrName>");
    }

    this.iQueryResponseData.append("</BillDetail></BillData>");
  }

  public void setBillDataNew(String aResult, int index, PaymentMerchantBean aPaymentMerchantBean) throws Exception {
    this.iQueryResponseData.append("<EBppData><Result>").append(aResult).append("</Result>");
    this.iQueryResponseData.append("<BillerNo>").append(MerchantConfig.getUniqueInstance().getPara().getMerchantID(index)).append("</BillerNo>");
    this.iQueryResponseData.append("<BillData><BillNo>").append(aPaymentMerchantBean.getTBillNo()).append("</BillNo>");
    this.iQueryResponseData.append("<BillName>").append(aPaymentMerchantBean.getTBillName()).append("</BillName>");
    ArrayList tArr = aPaymentMerchantBean.getTPayerValueList();
    this.iQueryResponseData.append("<PayerValue1>").append(tArr.get(0)).append("</PayerValue1>");
    if (tArr.size() == 2) {
      this.iQueryResponseData.append("<PayerValue2>").append(tArr.get(1)).append("</PayerValue2>");
    } else {
      this.iQueryResponseData.append("<PayerValue2></PayerValue2>");
    }

    this.iQueryResponseData.append("<Amount>").append(aPaymentMerchantBean.getTAmount()).append("</Amount>");
    this.iQueryResponseData.append("<EffectDate>").append(aPaymentMerchantBean.getTEffectDate()).append("</EffectDate>");
    this.iQueryResponseData.append("<ExpiredDate>").append(aPaymentMerchantBean.getTExpiredDate()).append("</ExpiredDate>");
    this.iQueryResponseData.append("<CreateDate>").append(aPaymentMerchantBean.getTCreateDate()).append("</CreateDate>");
    this.iQueryResponseData.append("<Remark>").append(aPaymentMerchantBean.getTRemark()).append("</Remark>");
    this.iQueryResponseData.append("<Status>").append(aPaymentMerchantBean.getTStatus()).append("</Status>");
    this.iQueryResponseData.append("<VerifyDomain>");
    ArrayList tArr1 = aPaymentMerchantBean.getTVerifyDomainList();

    for(int i = 0; i < tArr1.size(); ++i) {
      this.iQueryResponseData.append("<VerifyName" + (i + 1) + ">").append(tArr1.get(i)).append("</VerifyName" + (i + 1) + ">");
    }

    this.iQueryResponseData.append("</VerifyDomain>");
    this.iQueryResponseData.append("<BillDetail>");
    ArrayList tArr2 = aPaymentMerchantBean.getTBillDetailList();

    for(int i = 0; i < tArr2.size(); ++i) {
      this.iQueryResponseData.append("<BillAttrName>").append(tArr2.get(i)).append("</BillAttrName>");
    }

    this.iQueryResponseData.append("</BillDetail></BillData>");
    this.iQueryResponseData.append("</EBppData>");
  }

  public String getBase64MerchantNew(int index) throws Exception {
    SignService sign = SignService.getUniqueInstance();
    XMLDocument tXMLDocument = sign.signMessageXML(index, new XMLDocument(this.iQueryResponseData.toString()));
    String tMessage = "<?xml version=\"1.0\" encoding=\"gb2312\"?>" + tXMLDocument.toString();
    System.out.println(tMessage);
    Base64 tBase64 = new Base64();
    return tBase64.encode(tMessage.getBytes("gbk"));
  }

  public void setBillDataForConnectTest(PaymentMerchantBean aPaymentMerchantBean) {
    this.iQueryResponseData.append("<BillData><BillNo>").append(aPaymentMerchantBean.getTBillNo()).append("</BillNo>");
    this.iQueryResponseData.append("<BillName>").append(aPaymentMerchantBean.getTBillName()).append("</BillName>");
    ArrayList tArr = aPaymentMerchantBean.getTPayerValueList();
    this.iQueryResponseData.append("<PayerValue1>").append(tArr.get(0)).append("</PayerValue1>");
    if (tArr.size() == 2) {
      this.iQueryResponseData.append("<PayerValue2>").append(tArr.get(1)).append("</PayerValue2>");
    } else {
      this.iQueryResponseData.append("<PayerValue2></PayerValue2>");
    }

    this.iQueryResponseData.append("<Amount>").append(aPaymentMerchantBean.getTAmount()).append("</Amount>");
    this.iQueryResponseData.append("<EffectDate>").append(aPaymentMerchantBean.getTEffectDate()).append("</EffectDate>");
    this.iQueryResponseData.append("<ExpiredDate>").append(aPaymentMerchantBean.getTExpiredDate()).append("</ExpiredDate>");
    this.iQueryResponseData.append("<CreateDate>").append(aPaymentMerchantBean.getTCreateDate()).append("</CreateDate>");
    this.iQueryResponseData.append("<Remark>").append(aPaymentMerchantBean.getTRemark()).append("</Remark>");
    this.iQueryResponseData.append("<Status>").append(aPaymentMerchantBean.getTStatus()).append("</Status>");
    this.iQueryResponseData.append("<VerifyDomain>");
    ArrayList tArr1 = aPaymentMerchantBean.getTVerifyDomainList();

    for(int i = 0; i < tArr1.size(); ++i) {
      this.iQueryResponseData.append("<VerifyName>").append(tArr1.get(i)).append("</VerifyName>");
    }

    this.iQueryResponseData.append("</VerifyDomain>");
    this.iQueryResponseData.append("<BillDetail>");
    ArrayList tArr2 = aPaymentMerchantBean.getTBillDetailList();

    for(int i = 0; i < tArr2.size(); ++i) {
      this.iQueryResponseData.append("<BillAttrName>").append(tArr2.get(i)).append("</BillAttrName>");
    }

    this.iQueryResponseData.append("</BillDetail></BillData>");
  }

  public String getBase64Merchant(String aResult, String aMerchantID) throws Exception {
    StringBuffer tStr = new StringBuffer();
    tStr.append("<EBppData><Result>").append(aResult).append("</Result>");
    tStr.append("<BillerNo>").append(aMerchantID).append("</BillerNo>");
    tStr.append(this.iQueryResponseData.toString()).append("</EBppData>");
    SignService sign = SignService.getUniqueInstance();
    XMLDocument tXMLDocument = sign.signMessageXML(1, new XMLDocument(tStr.toString()));
    String tMessage = "<?xml version=\"1.0\" encoding=\"gb2312\"?>" + tXMLDocument.toString();
    Base64 tBase64 = new Base64();
    return tBase64.encode(tMessage.getBytes("gb2312"));
  }

  public String getBase64Merchant(String aResult, int i) throws Exception {
    StringBuffer tStr = new StringBuffer();
    tStr.append("<EBppData><Result>").append(aResult).append("</Result>");
    tStr.append("<BillerNo>").append(MerchantConfig.getUniqueInstance().getPara().getMerchantID(i)).append("</BillerNo>");
    tStr.append(this.iQueryResponseData.toString()).append("</EBppData>");
    System.out.println(this.iQueryResponseData);
    SignService sign = SignService.getUniqueInstance();
    XMLDocument tXMLDocument = sign.signMessageXML(i, new XMLDocument(tStr.toString()));
    String tMessage = "<?xml version=\"1.0\" encoding=\"gb2312\"?>" + tXMLDocument.toString();
    System.out.println(tMessage);
    Base64 tBase64 = new Base64();
    return tBase64.encode(tMessage.getBytes("gbk"));
  }

  public String getBase64MerchantForConnectTest() throws Exception {
    StringBuffer tStr = new StringBuffer();
    tStr.append("<EBppData><Result>").append("true").append("</Result>");
    tStr.append(this.iQueryResponseData.toString()).append("</EBppData>");
    XMLDocument tXMLDocument = new XMLDocument(tStr.toString());
    String tMessage = "<?xml version=\"1.0\" encoding=\"gb2312\"?>" + tXMLDocument.toString();
    Base64 tBase64 = new Base64();
    return tBase64.encode(tMessage.getBytes("gb2312"));
  }

  public QueryRequestBean getQueryReqeustBean() {
    return this.iQueryRequestBean;
  }
}
